"""
文件 PO
"""

from config import settings
from models import (
    AnyTypeBase,
    POBase,
)
from my_typing import *
from utils.data_utils.special import ObjectIdStr
from utils.validator_utils.pydantic_validator.field import (
    CharField,
    IntegerField,
    NormalField,
)


class FilePO(POBase):
    """ 文件 | PO """

    content_type: str = CharField("", title="文件类型", max_length=128)
    filename: str = CharField(..., title="自定义文件名", max_length=64)
    is_default: bool = NormalField(False, title="是否为默认文件（用户无法修改）")
    is_public: bool = NormalField(False, title="是否公开")
    raw_filename: str = CharField(..., title="原始文件名", max_length=512)
    remark: StrOrNone = CharField(None, title="备注", max_length=128)
    size: int = IntegerField(0, title="文件大小（Bytes）", max_value=settings.LIMIT.MAX_FILE_SIZE)
    suffix: str = CharField(..., title="文件后缀", max_length=16)
    user_id: ObjectIdStr | None = NormalField(..., title="用户 ID")


class FileGridPO(AnyTypeBase):
    """ 文件存储 | PO """

    id: ObjectIdStr = NormalField(..., title="主键（ObjectId）")
    content: bytes = NormalField(..., title="文件二进制内容")
